package com.codejoys.monitor.aspect;

import com.codejoys.monitor.Utils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

 @Aspect
 @Component
public class CanLibAspect {
    private static final Logger logger = LoggerFactory.getLogger(CanLibAspect.class);

    private static final String[] METHODS = {
        "TurnOnOffModule",
        "SetModuleVoltage",
        "SetModuleCurrent",
        "GetModuleVoltage",
        "GetModuleCurrent",
        "GetModuleTemperature",
        "GetModuleStatus"
    };

    @AfterReturning(returning = "value", pointcut = "execution(* com.codejoys.monitor.jna.CANLib.*(..)))")
    public void afterReturning(JoinPoint point, Object value) {
        // String method = point.getSignature().getName();
        // logger.debug("调用CANLIB方法：{}, 参数：{}", method, point.getArgs());
        // System.out.println("### canlib aspect:" + value);

        // 每个调用之后暂停20ms，CAN数据帧时间间隔
        Utils.trySleep(20);
    }
}
